#set($serviceClass=${strUtil.au($object)}+'Service')
#set($serviceVar=${strUtil.al($object)}+'Service')
#set($objectName=${strUtil.au($object)})
#set($objectVar=${strUtil.al($object)})
#set($paramClass=${strUtil.au($object)}+'Param')
#set($daoClass=${strUtil.au($object)}+'Dao')
#set($daoVar=${strUtil.al($object)}+'Dao')

package ${group}.${artifact}.${module}.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import ${group}.core.beans.MapParam;
import ${group}.core.exception.BusinessException;
import ${group}.core.rest.support.AbstractBaseService;
import ${group}.core.util.NumberUtil;
import ${group}.core.util.TimeUtil;

import ${group}.${artifact}.${module}.dal.dao.${daoClass};
import ${group}.${artifact}.${module}.dto.${objectName};
import ${group}.${artifact}.${module}.dto.${paramClass};



@Service
public class ${serviceClass} extends AbstractBaseService{

	@Autowired
	private ${daoClass} ${daoVar} ;
	
	@Override
	public void setMapper(){
		this.mapper = ${daoVar} ;
	}

#if(  ${apis.get("create")} &&  ${apis.get("create").enabled} )	
	#set($mp=${apis.get("create")})
	public int create${objectName}( ${paramClass} param ){
#if( $mp.uniques && $mp.uniques.size() > 0 )
#foreach( $unique in $mp.uniques )
		if( ${daoVar}.findMapBy("$unique" , param.${strUtil.getMethodName($unique)}() ) != null )
			throw new BusinessException("数据已存在") ;
#end
#end
		param.setCreateTime( TimeUtil.timestamp() );
		return NumberUtil.parse( ${daoVar}.createBean( param , ${paramClass}.class ), 0 ) ;
	}
#end	
#if(  ${apis.get("update")} &&  ${apis.get("update").enabled} )
	#set($mp=${apis.get("update")})
	public void update${objectName}( int ${mp.id} , ${paramClass} param ){
		if( ${daoVar}.findMapBy("${mp.id}", ${mp.id}, "${mp.id}") == null )
			throw new BusinessException("数据不存在!") ;
			
#if( $mp.uniques && $mp.uniques.size() > 0 )
		${objectName} ${objectVar} ;
#foreach( $unique in $mp.uniques )
		if( (${objectVar} = ${daoVar}.findBeanBy("${unique}" , param.${strUtil.getMethodName("$unique")}() ) ) != null 
			&&  ${mp.id} != ${objectVar}.${strUtil.getMethodName("${mp.id}")}() )
			throw new BusinessException("数据已存在") ;
#end
#end

		param.setUpdateTime( TimeUtil.timestamp() );
		${daoVar}.updateBean("${mp.id}", ${mp.id}, param ) ;
	}
#end	

#if(  ${apis.get("delete")} &&  ${apis.get("delete").enabled} )
	#set($mp=${apis.get("delete")})
	public int delete${objectName}( int ${mp.id} , int userId ){
		if( ${daoVar}.findMapBy("${mp.id}", ${mp.id}, "${mp.id}") == null )
			return 0 ;
		return ${daoVar}.updateMap("${mp.id}", ${mp.id} , new MapParam<String,Object>()
				.push("${mp.field}" , 1 )
				.push("updateTime" , TimeUtil.timestamp() )
				.push("updateId" , userId ) ) ;
	}
#end	

#if(  ${apis.get("status")} &&  ${apis.get("status").enabled} )
	#set($mp=${apis.get("status")})
	$mp.field
	public void setStatus( int ${mp.id} , int userId ){
		${objectName} ${objectVar} ;
		if( ( ${objectVar} = ${daoVar}.findBeanBy("${mp.id}", ${mp.id}, ${objectName}.class ) ) == null )
			throw new BusinessException("数据不存在!") ;
		${daoVar}.updateMap("${mp.id}" , ${mp.id} , new MapParam<String,Object>()
				.push("${mp.field}" , ${objectVar}.getStatus() > 0 ? 0 : 1 )
				.push("updateTime" , TimeUtil.timestamp() )
				.push("updateId" , userId ) ) ;
	}
#end
}
